<template>
  <div :bordered="false">
    <f-search-form :more="false" @searchHandler="searchHandler">
      <f-search-form-item label="批号" name="drugsLotNo"/>
    </f-search-form>
    <f-table ref="table" rowKey="drugsLotId" :columns="columns" :multiple="false" :operator="operator" :autoLoad="false" :params="queryParam" :api="api.drugslot">
        <span slot="action" slot-scope="text, record">
          <template>
<!--              <a @click="editDrugsLot(record)">编辑</a>-->
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.del(record)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <a-modal title="药品批号" :visible="lotModal" width="700px" @cancel="handleCancel" @ok="handleSubmit">
      <f-form ref="form" :action="api.drugslot" :form-key="this.formItem.drugsLotId">
        <f-form-item label="批号" name="drugsLotNo" :required="true" :value="formItem.drugsLotNo"/>
        <f-form-item label="成本价格" type="number" data-type="number" name="costPrice" :required="true" :value="formItem.costPrice"/>
        <f-form-item label="采购数量" type="number" name="drugsNum" dataType="number" :required="true" :value="formItem.drugsNum"/>
        <f-form-item label="采购日期" type="date" name="planDate" :required="true" :value="formItem.planDate"/>
      </f-form>
    </a-modal>
  </div>
</template>

<script>
  import api from './js/api'

  export default {
    name: 'DrugsLot',
    components: {},
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加',
        icon: 'plus',
        that: this,
        handler: function(table, that) {
          that.lotModal = true
          that.$refs.form.resetFields()
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        lotModal: false,
        formItem: {
          drugsLotId: '',
          drugsLotNo: '',
          drugsPrice: '',
          drugsNum: '',
          planDate: '',
          costPrice: ''
        },
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '批号',
            align: 'center',
            dataIndex: 'drugsLotNo'
          },
          {
            title: '成本价格',
            align: 'center',
            dataIndex: 'costPrice'
          },
          {
            title: '采购数量',
            align: 'center',
            dataIndex: 'drugsNum'
          },
          {
            title: '销售数量',
            align: 'center',
            dataIndex: 'saleNum'
          },
          {
            title: '剩余数量',
            align: 'center',
            dataIndex: 'surplusNum'
          },
          {
            title: '采购日期',
            align: 'center',
            dataIndex: 'planDate'
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      setData(data) {
        if (data && data.drugsId) {
          this.queryParam.drugsId = data.drugsId
          this.$refs['table'].refresh(false)
        }
      },
      editDrugsLot(bank) {
        this.formItem = bank
        this.lotModal = true
      },
      handleSubmit() {
        this.$refs.form.submit({ drugsId: this.queryParam.drugsId }, this.handleCancel)
      },
      handleCancel() {
        this.lotModal = false
      }
    }
  }
</script>